package servlets;

import java.io.IOException;
import java.util.List;

import javassist.expr.NewArray;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.mapping.Array;

import bean.ClienteVO;
import bean.OficinaDeVentaVO;

import cliente.BDelegate;

/**
 * Servlet implementation class MostrarClientes
 */
public class MostrarClientes extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MostrarClientes() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		BDelegate businessDelegate = new BDelegate();
		String numeroDeOficina;
		
		numeroDeOficina = request.getParameter("numeroDeOficina");
		
		OficinaDeVentaVO oficinaDeVenta = new OficinaDeVentaVO();
		oficinaDeVenta.setNroOficina(Integer.valueOf(numeroDeOficina));	
		
		OficinaDeVentaVO oficinaDeVentaAux = businessDelegate.obtenerOficina(oficinaDeVenta);		
		
		List<ClienteVO> clientes = businessDelegate.obtenerClientes(oficinaDeVentaAux);
		
		request.setAttribute("clientes", clientes);		
		
		RequestDispatcher requestDispatcher = request.getRequestDispatcher("ClientesDetalle.jsp");
		requestDispatcher.forward(request, response);
	}

}
